
.text
.data
.comm buffer,256,32
.comm x,4,32
.comm y,4,32

x:
	.long 30
y:
	.long 30

.section .rodata
.LC0:
	.string "%T"

.LC1:
	.string "expose-event"

.LC2:
	.string "destroy"

.LC3:
	.string "timer"



.text
.globl main

on_expose_event:
	pushq %rbp
	movq %rsp,%rbp
	subq $0x1000,%rsp

	movq %rdi,-0x1000(%rbp) /* widget */
	movq %rsi,-0xff8(%rbp) /* event */
	movq %rdx,-0xff0(%rbp) /* data */

	movq $0,-0xfe0(%rbp) /* cr */

	movq -0x1000(%rbp),%rdi /* widget */
	movq 80(%rdi),%rdi /* widget->window */
	movl $0,%eax 
	call gdk_cairo_create 
	movq %rax,-0xfe0(%rbp) /* cr */

	movl $30,%eax
	movl x(%rip),%eax
	cvtsi2sd %eax,%xmm1
	cvtsi2sd %eax,%xmm0
	movq -0xfe0(%rbp),%rdi  /* cr */
	call cairo_move_to 
	addl $3,x(%rip)

	leaq buffer(%rip),%rsi 
	movq -0xfe0(%rbp),%rdi /* cr */
	call cairo_show_text 

	movq -0xfe0(%rbp),%rdi /* cr */
	call cairo_destroy 

	movl $0,%eax
	leave
	ret

time_handler:
	pushq %rbp
	movq %rsp,%rbp
	subq $0x1000,%rsp

	movq %rdi,-0x1000(%rbp) /* widget */
	movq $0,-0xff8(%rbp) /* loctime */
	movq $0,-0xff0(%rbp) /* curtime */

	movq -0x1000(%rbp),%rdi /* widget */
	cmpq $0,80(%rdi) /* widget->window */
	jne .Ltime_handler_400
	
	movl $0,%eax
	jmp .Ltime_handler_0 

.Ltime_handler_400:
	movl $0,%edi
	call time 
	movq %rax,-0xff0(%rbp)  /* curtime */

	leaq -0xff0(%rbp),%rdi /* curtime */
	call localtime 
	movq %rax,-0xff8(%rbp) /* loctime*/

	movq -0xff8(%rbp),%rcx /* locatime */
	leaq .LC0(%rip),%rdx
	movl $256,%esi 
	leaq buffer(%rip),%rdi 
	call strftime 
	
	movq -0x1000(%rbp),%rdi /* widget */
	call gtk_widget_queue_draw
	movl $1,%eax
.Ltime_handler_0:
	leave
	ret

main:
	pushq %rbp
	movq %rsp,%rbp
	subq $0x1000,%rsp

	movl %edi,-0x1000(%rbp) /* argc */
	movq %rsi,-0xff8(%rbp) /* argv */

	movq $0,-0xff0(%rbp) /* window */
	movq $0,-0xfe8(%rbp) /* darea */

	leaq -0xff8(%rbp),%rsi /* argv */
	leaq -0x1000(%rbp),%rdi /* argc */
	call gtk_init 

	movl $0,%edi
	call gtk_window_new 
	movq %rax,-0xff0(%rbp) /* window */

	call gtk_drawing_area_new
	movq %rax,-0xfe8(%rbp) /* darea */

	call gtk_container_get_type 
	movq %rax,%rsi
	movq -0xff0(%rbp),%rdi /* window */
	call g_type_check_instance_cast 
	movq -0xfe8(%rbp),%rsi /* darea */
	movq %rax,%rdi 
	call gtk_container_add 

	movl $0,%r9d
	movl $0,%r8d 
	movl $0,%ecx
	leaq on_expose_event(%rip),%rdx 
	leaq .LC1(%rip),%rsi
	movq -0xfe8(%rbp),%rdi /* darea */
	call g_signal_connect_data 

	movl $0,%r9d
	movl $0,%r8d 
	movl $0,%ecx
	movq gtk_main_quit@GOTPCREL(%rip),%rdx
	leaq .LC2(%rip),%rsi
	movq -0xff0(%rbp),%rdi /* window */
	call g_signal_connect_data 

	call gtk_window_get_type 
	movq %rax,%rsi
	movq -0xff0(%rbp),%rdi /* window */
	call g_type_check_instance_cast 
	movl $1,%esi
	movq %rax,%rdi
	call gtk_window_set_position 

	call gtk_window_get_type 
	movq %rax,%rsi
	movq -0xff0(%rbp),%rdi /* window */
	call g_type_check_instance_cast 
	movl $600,%edx
	movl $770,%esi 
	movq %rax,%rdi
	call gtk_window_set_default_size 

	call gtk_window_get_type 
	movq %rax,%rsi
	movq -0xff0(%rbp),%rdi /* window */
	call g_type_check_instance_cast 
	leaq .LC3(%rip),%rsi
	movq %rax,%rdi
	call gtk_window_set_title 

	movq -0xff0(%rbp),%rdx /* window */
	leaq time_handler(%rip),%rsi
	movl $100,%edi
	call g_timeout_add 

	movq -0xff0(%rbp),%rdi /* window*/
	call gtk_widget_show_all 

	movq -0xff0(%rbp),%rdi /* window*/
	call time_handler 

	call gtk_main

	movl $0,%eax
	leave
	ret
